package org.teachertools.data;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

@Entity
public class Note implements Serializable {
    private static final long serialVersionUID = 1515771487281175680L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(nullable = false, length = 10)
    private String note;

    @Column(nullable = true, length = 200)
    private String commentaire;

    @Temporal(value = TemporalType.DATE)
    private Date dateNote;

    @Transient
    private Date finDateNote;

    @ManyToOne(optional = false)
    @JoinColumn(name = "ID_COMPETENCE")
    private org.teachertools.data.Competence competence;

    @ManyToOne(optional = false)
    @JoinColumn(name = "ID_ELEVE")
    private org.teachertools.data.Eleve eleve;

    public Note() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long pId) {
        this.id = pId;
    }

    public String getNote() {
        return this.note;
    }

    public void setNote(String pNote) {
        this.note = pNote;
    }

    public String getCommentaire() {
        return this.commentaire;
    }

    public void setCommentaire(String pCommentaire) {
        this.commentaire = pCommentaire;
    }

    public Date getDateNote() {
        return this.dateNote;
    }

    public void setDateNote(Date pDateNote) {
        this.dateNote = pDateNote;
    }

    public Date getFinDateNote() {
        return this.finDateNote;
    }

    public void setFinDateNote(Date pFinDateNote) {
        this.finDateNote = pFinDateNote;
    }

    public org.teachertools.data.Competence getCompetence() {
        return this.competence;
    }

    public void setCompetence(org.teachertools.data.Competence pCompetence) {
        this.competence = pCompetence;
    }

    public org.teachertools.data.Eleve getEleve() {
        return this.eleve;
    }

    public void setEleve(org.teachertools.data.Eleve pEleve) {
        this.eleve = pEleve;
    }

    @Override
    public int hashCode() {
        HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
        hashCodeBuilder.append(this.id);
        hashCodeBuilder.append(this.eleve.getId());
        hashCodeBuilder.append(this.competence.getId());
        hashCodeBuilder.append(this.dateNote);
        return hashCodeBuilder.toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if ((obj instanceof Note) == false) {
            return false;
        }
        Note otherNote = (Note) obj;
        if (otherNote == this) {
            return true;
        }
        EqualsBuilder equalsBuilder = new EqualsBuilder();
        equalsBuilder.append(this.id, otherNote.getId());
        return equalsBuilder.isEquals();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).append("note", getNote()).toString();
    }
}
